/**
 *需要暴露出来，公共使用的系统库 ,存放路径在js
 */
var paths = {
	jquery: "js/jquery",
	editor: "js/editor",
	sys: "js/sys",
	vue: "js/vue",
	bootstrap: "js/bootstrap.min",
	validate: "js/validate",
	auto: "js/bootstrap.autocomplete",
	viewer: "js/viewer"
};

require.config({
	paths: paths,
	urlArgs: "t=" + (new Date()).getTime(), //不缓存，运行时，请删除
	map: {
		'*': {
			'css': 'js/css.min'
		}
	},
	shim: {
		'date': {
			deps: ['jquery', "css!js/datetimepicker/css/bootstrap-datetimepicker.min.css",
				"js/datetimepicker/bootstrap-datetimepicker.min",
				"js/datetimepicker/locales/bootstrap-datetimepicker.zh-CN"
			],
			exports: '$'
		}
	}
});

require(["js/main"],function(main){
	main();
});

/**
 * 将日期对象格式化成字符串
 * @param {String} format 格式支持：yyyy-MM-dd HH:mm:ss.S 默认：yyyy-MM-dd
 */
Date.prototype.format = function(format) {
	format = format == null ? "yyyy-MM-dd" : format;
	var o = {
		"M+": this.getMonth() + 1, //month
		"d+": this.getDate(), //day
		"H+": this.getHours(), //hour
		"m+": this.getMinutes(), //minute
		"s+": this.getSeconds(), //second
		"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
		"S": this.getMilliseconds() //millisecond
	}

	if(/(y+)/.test(format))
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("(" + k + ")").test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}

/**
 * 将字符串格式化成日期对象
 * @param {String} format 格式支持：yyyy-MM-dd HH:mm:ss.S 默认：yyyy-MM-dd
 */
String.prototype.toDate = function(format) {
	format = format == null ? "yyyy-MM-dd" : format;
	var d = new Date();
	var o = {
		"y+": "d.setYear(val)", //year
		"M+": "d.setMonth(val-1)", //month
		"d+": "d.setDate(val)", //day
		"H+": "d.setHours(val)", //hour
		"m+": "d.setMinutes(val)", //minute
		"s+": "d.setSeconds(val)", //second
		"S+": "d.setMilliSeconds(val)" //millisecond
	}
	var regx = format
	for(var k in o) {
		if(new RegExp("(" + k + ")").test(format))
			regx = regx.replace(new RegExp(k), "[0-9]+");
	}

	if(!new RegExp("^" + regx + "$").test(this)) {
		throw "日期格式不正确:" + format;
	}

	for(var k in o) {
		if(new RegExp("(" + k + ")").test(format)) {
			var regx = format;
			for(var temp in o) {
				if(temp == k) {
					regx = regx.replace(new RegExp(temp), "([0-9]+)");
				} else {
					regx = regx.replace(new RegExp(temp), "[0-9]+");
				}

			}
			var val = Number(this.replace(new RegExp("^" + regx + "$"), "$1"));
			try {

				if(k == "S+") {
					d.setMilliseconds(val);
				} else {
					eval(o[k].replace("val", val));
				}
			} catch(e) {
				alert(e);
			}
		} else {
			try {
				var val = k == "M+" ? 1 : 0;
				if(k == "S+") {
					d.setMilliseconds(val);
				} else {
					eval(o[k].replace("val", val));
				}
			} catch(e) {
				alert(e);
			}
		}
	}
	return d;
}